from common.db import models
from celery.result import AsyncResult



class TaskProcess(models.Model):
    class Meta:
        verbose_name = verbose_name_plural = '任务进度'

    task_callable = models.CharField(verbose_name='调用函数')
    task_name = models.CharField(verbose_name='任务名字')
    task_id = models.CharField(verbose_name='task_id')

    @property
    def task_result(self):
        return AsyncResult(id=self.task_id)

    @property
    def status(self):
        return self.task_result.status if self.task_result else ''


